#include <cstdio>
#include <cstring>

const int N = 155, inf = 0x3f3f3f3f;
int n, m;
int e_cnt, heads[N], vis[N], match[N << 1];

struct Edge {
  int v, nxt;
} e[6005];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

bool dfs(int x, int tim) {
  if (vis[x] == tim) return false;
  vis[x] = tim;
  for (int i = heads[x], v; i; i = e[i].nxt) {
    if (!match[v = e[i].v] || dfs(match[v], tim)) {
      match[v] = x;
      match[x] = v;
      return true;
    }
  }
  return false;
}

void print(int x) {
  printf("%d ", x);
  vis[x] = true;
  if (match[x]) print(match[x] - n);
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P2764 最小路径覆盖问题.in", "r", stdin);
  freopen("P2764 最小路径覆盖问题.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; ++i) scanf("%d%d", &u, &v), add(u, v + n);
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (dfs(i, i)) ++ans;
  memset(vis, 0, sizeof(vis));
  bool flag;
  do {
    flag = false;
    for (int i = 1; i <= n; ++i) {
      if (!vis[i] && match[i] && !match[i + n]) flag = true, print(i), puts("");
    }
  } while (flag);
  printf("%d", n - ans);
  return 0;
}